import 'dart:ui';

import 'package:flustars/flustars.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class ThemeProvider extends ChangeNotifier {

  static const Map<ThemeMode, String> themes = {
    ThemeMode.dark: 'Dark', ThemeMode.light : 'Light', ThemeMode.system : 'System'
  };
  
  void syncTheme() {
    String theme = SpUtil.getString('AppTheme');
    if (theme.isNotEmpty && theme != themes[ThemeMode.system]) {
      notifyListeners();
    }
  }

  void setTheme(ThemeMode themeMode) {
    SpUtil.putString('AppTheme', themes[themeMode]);
    notifyListeners();
  }

  ThemeMode getThemeMode(){
    String theme = SpUtil.getString('AppTheme');
    switch(theme) {
      case 'Dark':
        return ThemeMode.dark;
      case 'Light':
        return ThemeMode.light;
      default:
        return ThemeMode.system;
    }
  }

  getTheme({bool isDarkMode: false}) {
    return ThemeData(
      primaryColor: isDarkMode ? AppThemeColor.dark_textColor : AppThemeColor.textColor,                        //默认文字颜色
      cardColor: isDarkMode ? AppThemeColor.dark_textSubColor : AppThemeColor.textSubColor,                        //默认二级文字颜色
      hoverColor: isDarkMode ? AppThemeColor.dark_textColorfff : AppThemeColor.textColorfff,                       //白色文字
      scaffoldBackgroundColor: isDarkMode ? AppThemeColor.dark_bodyBackgroundColor : AppThemeColor.bodyBackgroundColor,   //页面背景色
      primaryColorLight: isDarkMode ? AppThemeColor.dark_appBarColor : AppThemeColor.appBarColor,                 //appbar颜色
      primaryColorDark: isDarkMode ? AppThemeColor.dark_appBarTextColor : AppThemeColor.appBarTextColor,              //appbar文字颜色
      bottomAppBarColor: isDarkMode ? AppThemeColor.dark_bottomBarColor : AppThemeColor.bottomBarColor,           //bottomBar颜色
      dividerColor: isDarkMode ? AppThemeColor.dark_cardBgmColor : AppThemeColor.cardBgmColor,                     //容器背景颜色
      hintColor: isDarkMode ? AppThemeColor.dark_bottomLineColor : AppThemeColor.bottomLineColor,                  //0.5px下划线颜色
      secondaryHeaderColor: isDarkMode ? AppThemeColor.dark_userBackgroundColor : AppThemeColor.userBackgroundColor,                  //用户中心背景颜色

      //剩余未使用颜色
      // Color canvasColor,
      // Color focusColor,
      // Color highlightColor,
      // Color splashColor,
      // Color accentColor,
      // Color selectedRowColor,
      // Color unselectedWidgetColor,
      // Color disabledColor,
      // Color buttonColor,
      // Color secondaryHeaderColor,
      // Color textSelectionColor,
      // Color cursorColor,
      // Color textSelectionHandleColor,
      // Color backgroundColor,
      // Color dialogBackgroundColor,
      // Color indicatorColor,
      // Color errorColor,
      // Color toggleableActiveColor,
    );
  }
}

class AppThemeColor {
  static const Color textColor = Color(0xff333333);               //默认文字颜色
  static const Color dark_textColor = Color(0xff707070);

  static const Color textSubColor = Color(0xff888888);               //默认二级文字颜色
  static const Color dark_textSubColor = Color(0xff707070);

  static const Color appBarColor = Color(0xff333333);               //appBar颜色
  static const Color dark_appBarColor = Color(0xff252525);

  static const Color appBarTextColor = Color(0xffffffff);               //appBar文字颜色,返回按钮和右边按钮一律使用这个颜色
  static const Color dark_appBarTextColor = Color(0xff707070);

  static const Color bottomBarColor = Color(0xff333333);               //appBottomBar背景颜色
  static const Color dark_bottomBarColor = Color(0xff1a1a1a);

  static const Color bodyBackgroundColor = Color(0xffffffff);               //页面背景色
  static const Color dark_bodyBackgroundColor = Color(0xff252525);

  static const Color cardBgmColor = Color(0xffffffff);               //容器背景颜色
  static const Color dark_cardBgmColor = Color(0xff252525);

  static const Color textColorfff = Color(0xffffffff);               //文字白色
  static const Color dark_textColorfff = Color(0xff888888);

  static const Color userBackgroundColor = Color(0xff171a1c);               //用户中心背景颜色
  static const Color dark_userBackgroundColor = Color(0xff171a1c);

  static const Color bottomLineColor = Color.fromARGB(50, 0, 0, 0);  //0.5px下划线颜色
  static const Color dark_bottomLineColor = Color.fromARGB(50, 255, 255, 255);
}
